<template>
	<view class="u-page">
		<view class="userinfo">
			<image src="https://ew6.cn/sbss.png" style="border-radius: 50%;"></image>
			<view class="hello">欢迎登录</view>
		</view>
		<view class="search" @click="search">
			<u-icon name="search" color="#000" size="40"></u-icon>
		</view>
		<view class="project">
			<view class="mini" @click="add">
				<view class="add">
					<u-icon name="plus-circle" color="#05BDC1" size="50"></u-icon>
					<view class="address" style="margin-top: 10px;">添加分组</view>
				</view>
			</view>
			<view class="mini" v-for="(item,index) in list" :key="index">
				<view class="mine-top" @click="look(item)">
					<image src="https://ew6.cn/sbss.png" style="width: 90rpx;height: 80rpx;"></image>
					<view class="address">{{item.name}}</view>
				</view>
				<view class="mini-middle" @click="look(item)">
					<view class="project-tip-id">分组ID</view>
					<view class="project-id">{{item.id}}</view>
					<view>装机数 <span>{{item.alarmsCount}}</span></view>
				</view>
				<view class="mini-bottom">
					<u-icon name="edit-pen" color="#000" size="30" @click="look(item)"></u-icon>
					<u-icon name="map" color="#000" size="30"></u-icon>
					<u-icon name="order" color="#000" size="30" @click="order(item)"></u-icon>
					<u-icon name="trash" color="#DC143C" size="30" @click="deleteDevice()"></u-icon>
				</view>
			</view>
		</view>

		<u-modal :content="content" :show="showDelete" showCancelButton closeOnClickOverlay @confirm="confirm"
			@cancel="cancel" @close="close"></u-modal>
	</view>
</template>

<script>
	import {
		listToMiniApp,
		getInfo
	} from '../../api/index.js'
	export default {
		data() {
			return {
				list: [],
				content: '确定删除吗',
				showDelete: false
			}
		},
		created() {
			//#ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			//#endif
		},
		onLoad() {
			// this.Info()
			this.getList()
		},
		onReady() {

		},
		methods: {
			test() {
				uni.navigateTo({
					url: 'controlHome'
				})
			},
			Info() {
				getInfo().then(res => {

				})
			},
			getList() {
				listToMiniApp().then(res => {
					console.log(res)
					this.list = res.data
				})
			},
			add() {
				uni.navigateTo({
					url: '/pageIndex/pages/index/edit'
				})
			},
			search() {
				uni.navigateTo({
					url: '/pageIndex/pages/index/list'
				})
			},
			order(item) {
				console.log(item)
				// uni.navigateTo({
				// 	url:'/pageIndex/pages/index/baobiao/baobiao'
				// })
			},
			look(item) {
				// uni.navigateTo({
				// 	url: '../../pageIndex/pages/index/look?id='+item.id +'&name='+item.name,
				// })
				uni.navigateTo({
					url: '/pageIndex/pages/index/look?id=' + item.id + '&name=' + item.name,
				})
			},
			confirm() {
				const _this = this
				setTimeout(function() {
					_this.showDelete = false
				}, 1000)
			},
			cancel() {
				this.showDelete = false
			},
			close() {
				this.showDelete = false
			},
			deleteDevice() {
				this.showDelete = true
			}
		},
	}
</script>

<style lang="scss">
	.userinfo {
		display: flex;
		align-items: center;
		width: 90%;
		height: 100rpx;
		margin-left: 5%;
		font-size: 30rpx;

		image {
			width: 100rpx;
			height: 100rpx;
		}

		.hello {
			margin-left: 30rpx;
			font-weight: 800;
		}
	}

	.search {
		display: flex;
		justify-content: flex-end;
		margin-top: -60rpx;
		margin-bottom: 20rspx;

		image {
			width: 50rpx;
			height: 50rpx;
			margin-right: 100rpx;
		}
	}

	.project {
		width: 100%;
		display: flex;
		flex-wrap: wrap;

		.mini {
			position: relative;
			padding-left: 10rpx;
			padding-right: 10rpx;
			width: 40%;
			height: 300rpx;
			border: 1px solid #ccc;
			border-radius: 20rpx;
			margin-left: 5%;
			margin-bottom: 20rpx;

			background: linear-gradient(to bottom right, #eafefd, #fff);

			image {
				width: 50rpx;
				height: 50rpx;
			}

			.add {
				width: 100%;
				height: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				font-size: 30rpx;

				image {
					width: 100rpx;
					height: 100rpx;
					margin-bottom: 20rpx;
				}

			}

			.mine-top {
				display: flex;
				align-items: center;
				margin-top: 10rpx;

				image {
					width: 120rpx;
					height: 80rpx;
				}

				.address {
					font-size: 24rpx;
					margin-left: 20rpx;
				}
			}

			.mini-middle {
				margin-top: 10rpx;
				font-size: 22rpx;
				color: #33332B;

				.project-tip-id {
					font-size: 24rpx;
					margin-bottom: 10rpx;
				}

				.project-id {
					font-size: 26rpx;
					margin-bottom: 10rpx;
				}
			}

			.mini-bottom {
				margin-top: 20rpx;
				display: flex;
				justify-content: space-between;
			}
		}
	}
</style>